﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SimTank
{
    public partial class SimTankMainWindow : Form
    {
        

        public SimTankMainWindow()
        {
            InitializeComponent();
            PopulateHashtable();
            PopulateAbilityList();
        }

        private void TankModel_SelectedIndexChanged(object sender, EventArgs e)
        {
            PriorityList.Items.Clear();
            AllAbilitiesList.Items.Clear();
            foreach (attackQueueObject attackQueueBuild in attackList)
            {
                if (attackQueueBuild.usableby.Equals(TankModel.Text))
                {
                    AllAbilitiesList.Items.Add(attackQueueBuild.ToListViewItem());
                }
            }
        }

        private void PriorityMoveRight_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in AllAbilitiesList.SelectedItems)
            {
                ListViewItem clone = (ListViewItem)item.Clone();
                clone.Tag = null;
                PriorityList.Items.Add(clone);
            }
            PriorityList.Invalidate();
        }

        private void PriorityMoveLeft_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in PriorityList.SelectedItems)
            {
                PriorityList.Items.Remove(item);
            }
            PriorityList.Invalidate();
        }

        private void PriorityUp_Click(object sender, EventArgs e)
        {
            if (PriorityList.SelectedIndices[0] != 0)
            {
                foreach (int index in PriorityList.SelectedIndices)
                {
                    ListViewItem tmp = (ListViewItem)PriorityList.Items[index - 1].Clone();
                    PriorityList.Items[index - 1] = (ListViewItem)PriorityList.Items[index].Clone();
                    PriorityList.Items[index] = tmp;
                    PriorityList.Items[index].Tag = null;
                    PriorityList.Items[index - 1].Tag = null;
                }
            }
            PriorityList.Invalidate();
        }

        private void PriorityDown_Click(object sender, EventArgs e)
        {
            if (PriorityList.SelectedIndices[PriorityList.SelectedIndices.Count-1] != PriorityList.SelectedIndices.Count-1)
            {
                for (int iteratorindex = PriorityList.SelectedIndices.Count - 1; iteratorindex >= 0; iteratorindex--)
                {
                    int index = PriorityList.SelectedIndices[iteratorindex];
                    ListViewItem tmp = (ListViewItem)PriorityList.Items[index + 1].Clone();
                    PriorityList.Items[index + 1] = (ListViewItem)PriorityList.Items[index].Clone();
                    PriorityList.Items[index] = tmp;
                    PriorityList.Items[index].Tag = null;
                    PriorityList.Items[index + 1].Tag = null;
                }
            }
            PriorityList.Invalidate();
        }
    }
}
